2020-2021 Sunseeker Telemetry and Lighting System
timer_d_ex2_overflowISR.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430F51x2 Demo - TimerD0, Toggle P1.0, Overflow ISR, DCO SMCLK
34 //
35 // Description: Toggle P1.0 using software and TimerD0 overflow ISR.
36 // In this example an ISR triggers when TD overflows. Inside the TD
37 // overflow ISR P1.0 is toggled. Toggle rate is approximatlely 16Hz.
38 // Proper use of the TDIV interrupt vector generator is demonstrated.
39 // ACLK = n/a, MCLK = SMCLK = TDCLK = default DCO ~1.045MHz
40 //
41 // MSP430F51x2
42 // ---------------
43 // /|\| |
44 // | | |
45 // --|RST |
46 // | |
47 // | P1.0|-->LED
48 //
49 //******************************************************************************
50 #include "driverlib.h"
51 
52 void main(void)
53 {
54  //Stop WDT
55  WDT_A_hold(WDT_A_BASE);
56 
57  //Set P1.0 to output direction
58  GPIO_setAsOutputPin(
59  GPIO_PORT_P1,
60  GPIO_PIN0
61  );
62 
63  Timer_D_clearTimerInterrupt(TIMER_D0_BASE);
64 
65  Timer_D_initContinuousModeParam param = {0};
66  param.clockSource = TIMER_D_CLOCKSOURCE_SMCLK;
67  param.clockSourceDivider = TIMER_D_CLOCKSOURCE_DIVIDER_1;
68  param.clockingMode = TIMER_D_CLOCKINGMODE_EXTERNAL_CLOCK;
69  param.timerInterruptEnable_TDIE = TIMER_D_TDIE_INTERRUPT_ENABLE;
70  param.timerClear = TIMER_D_DO_CLEAR;
71  Timer_D_initContinuousMode(TIMER_D0_BASE, &param);
72 
73  Timer_D_startCounter(TIMER_D0_BASE,
74  TIMER_D_CONTINUOUS_MODE
75  );
76 
77  __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
78  __no_operation(); // For debugger
79 }
80 
81 // Timer0_D1 Interrupt Vector (TDIV) handler
82 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
83 #pragma vector=TIMER0_D1_VECTOR
84 __interrupt
85 #elif defined(__GNUC__)
86 __attribute__((interrupt(TIMER0_D1_VECTOR)))
87 #endif
88 void TIMER0_D1_ISR(void)
89 {
90  switch(__even_in_range(TD0IV,30))
91  {
92  case 0: break; // No interrupt
93  case 2: break; // CCR1 not used
94  case 4: break; // CCR2 not used
95  case 6: break; // reserved
96  case 8: break; // reserved
97  case 10: break; // reserved
98  case 12: break; // reserved
99  case 14: break;
100  case 16: // overflow
101  GPIO_toggleOutputOnPin(
102 
103  GPIO_PORT_P1,
104  GPIO_PIN0
105  );
106  break;
107  case 18: break; // Clock fail low
108  case 20: break; // Clock fail high
109  case 22: break; // Hi-res freq locked
110  case 24: break; // Hi-res freq unlocked
111  case 26: break; // reserved
112  case 28: break; // reserved
113  case 30: break; // reserved
114  default: break;
115  }
116 }
117 
MPU_initThreeSegmentsParam param
__no_operation()
void main(void)
void TIMER0_D1_ISR(void)